<?php

  if(!isBlank($_GET['cntonly']))
  {
    $_FLAGS['ContentOnly'] = 'y';
    $PageTitle = '"";';

    function addActionsGetItem()
  	{
  	  global $Item, $WorkTableKeyFieldName;

  	  $Item[$WorkTableKeyFieldName] = 1;
  	}
  }

  if($_GET['tsk'] == 'get_regions')
  {

  	if($_GET['resize_win'] == 'y')
  	{
  	  $_FLAGS['ResizeWindowToContentParams'] = __TRUE;
  	}

    $_FLAGS['NoReadDB'] = __TRUE;
    $TabFields['r'] = getFieldNamesWithLangs($_SQL_TABLE['region'], array('title'));
    $RegionsSelect = array_kv(getTableAsArray($_SQL_TABLE['region'], 'id', array(), '', 'id,'.$TabFields['r']['title']), $TabFields['r']['title'], 'id');

    $_SQL_TABLE_FIELDS[$GlobPart]['regions'] = array(

								'type' => 'checkboxes',
								'title' => $language['admin']['regions'],
								'separator' => '<br />',
								'useInAddForm' => 'y',
								'addVariable' => $_POST['regions'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => $RegionsSelect,
								'required' => $CONFIG['AdminReqPatAll'],
								'selected' => explode($CONFIG['AdminListInRowDelim'], $_GET['currval']),
								'joinFunc' => 'y',
								'parentElemID' => '',
								'parentWindowName' => '',
								'position' => 'vertical',
    );

    $NoUse['BackButton'] = 'y';
    $NoUse['SaveItemButton'] = 'y';
    $ItemButtons['makeJoinVals'] = array(
  												'cssClass' => '',
  												'newRow' => '',
  												'value' => $language['admin']['doneButton'],
  												'onclick' => 'joinElementsregions(\''.$CONFIG['AddFormName'].'\');window.close();',
    );
  }
  elseif($_GET['tsk'] == 'get_rubrics')
  {

  	if($_GET['resize_win'] == 'y')
  	{
  	  $_FLAGS['ResizeWindowToContentParams'] = __TRUE;
  	}

    $_FLAGS['NoReadDB'] = __TRUE;
    $TabFields['r'] = getFieldNamesWithLangs($_SQL_TABLE['rubric'], array('title'));
    $Params = array();
    if(!isBlank($_GET['rubric']))
    {      $Params[] = "id IN ('".str_replace($CONFIG['AdminListInRowDelim'], "','", $_GET['rubric'])."')";
    }
    $RubricsSelect = array_kv(getTableAsArray($_SQL_TABLE['rubric'], 'position', $Params, '', 'id,'.$TabFields['r']['title']), $TabFields['r']['title'], 'id');

    $_SQL_TABLE_FIELDS[$GlobPart]['rubrics'] = array(

								'type' => 'checkboxes',
								'title' => $language['admin']['rubrics'],
								'separator' => '<br />',
								'useInAddForm' => 'y',
								'addVariable' => $_POST['rubrics'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => $RubricsSelect,
								'required' => $CONFIG['AdminReqPatAll'],
								'selected' => explode($CONFIG['AdminListInRowDelim'], $_GET['currval']),
								'joinFunc' => 'y',
								'parentElemID' => '',
								'parentWindowName' => '',
								'position' => 'vertical',
    );

    $NoUse['BackButton'] = 'y';
    $NoUse['SaveItemButton'] = 'y';
    $ItemButtons['makeJoinVals'] = array(
  												'cssClass' => '',
  												'newRow' => '',
  												'value' => $language['admin']['doneButton'],
  												'onclick' => 'joinElementsrubrics(\''.$CONFIG['AddFormName'].'\');window.close();',
    );
  }
  elseif($_GET['tsk'] == 'get_blocks')
  {

  	if($_GET['resize_win'] == 'y')
  	{
  	  $_FLAGS['ResizeWindowToContentParams'] = __TRUE;
  	}

    $NewsType = $_GET['news_type'];
    $_FLAGS['NoReadDB'] = __TRUE;
    $TabFields['b'] = getFieldNamesWithLangs($_SQL_TABLE['block'], array('title'));
    $Params = array("news_block = 'y'", "news_type = '".$NewsType."'");
    if(!isBlank($_GET['block']))
   	{
      $Params[] = "id IN ('".str_replace($CONFIG['AdminListInRowDelim'], "','", $_GET['block'])."')";

    }
    $BlocksSelect = array_kv(getTableAsArray($_SQL_TABLE['block'], 'id', $Params, '', 'id,'.$TabFields['b']['title']), $TabFields['b']['title'], 'id');

    $_SQL_TABLE_FIELDS[$GlobPart]['blocks'] = array(

								'type' => 'checkboxes',
								'title' => $language['admin']['blocks'],
								'separator' => '<br />',
								'useInAddForm' => 'y',
								'addVariable' => $_POST['blocks'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => $BlocksSelect,
								'required' => $CONFIG['AdminReqPatAll'],
								'selected' => explode($CONFIG['AdminListInRowDelim'], $_GET['currval']),
								'joinFunc' => 'y',
								'parentElemID' => '',
								'parentWindowName' => '',
								'position' => 'vertical',
    );

    $NoUse['BackButton'] = 'y';
    $NoUse['SaveItemButton'] = 'y';
    $ItemButtons['makeJoinVals'] = array(
  												'cssClass' => '',
  												'newRow' => '',
  												'value' => $language['admin']['doneButton'],
  												'onclick' => 'joinElementsblocks(\''.$CONFIG['AddFormName'].'\');window.close();',
    );
  }
  elseif($_GET['tsk'] == 'get_keywords')
  {

  	if($_GET['resize_win'] == 'y')
  	{
  	  $_FLAGS['ResizeWindowToContentParams'] = __TRUE;
  	}

    $_FLAGS['NoReadDB'] = __TRUE;
    $TabFields['k'] = getFieldNamesWithLangs($_SQL_TABLE['keyword'], array('title'));
    $TabFields['kg'] = getFieldNamesWithLangs($_SQL_TABLE['keyword_group'], array('title'));
    $KeywordGroupsSelect = array_kv(getTableAsArray($_SQL_TABLE['keyword_group'], 'id', array(), '', 'id,'.$TabFields['kg']['title']), $TabFields['kg']['title'], 'id');
    $Keywords = getTableAsArray($_SQL_TABLE['keyword'], $TabFields['k']['title'], array(), '', 'id,keyword_group,'.$TabFields['k']['title']);
    $KeywordsSelect = array();
    foreach($Keywords as $n => $keyword)
    {      $KeywordsSelect[$keyword['keyword_group']][] = $keyword;
    }
    foreach($KeywordsSelect as $n => $arr)
    {      $KeywordsSelect[$n] = array_kv($arr, $TabFields['k']['title'], 'id');
    }


    $_SQL_TABLE_FIELDS[$GlobPart]['keywords'] = array(

								'type' => 'multicheckboxes',
								'title' => $language['admin']['keywords'],
								'separator' => '<br />',
								'useInAddForm' => 'y',
								'addVariable' => $_POST['keywords'],
								'useInList' => $CONFIG['useInListSort'],
								'titleValues' => $KeywordGroupsSelect,
								'values' => $KeywordsSelect,
								'required' => $CONFIG['AdminReqPatAll'],
								'selected' => explode($CONFIG['AdminListInRowDelim'], $_GET['currval']),
								'joinFunc' => 'y',
								'parentElemID' => '',
								'parentWindowName' => '',
								'position' => 'vertical',
    );

    $NoUse['BackButton'] = 'y';
    $NoUse['SaveItemButton'] = 'y';
    $ItemButtons['makeJoinVals'] = array(
  												'cssClass' => '',
  												'newRow' => '',
  												'value' => $language['admin']['doneButton'],
  												'onclick' => 'joinElementskeywords(\''.$CONFIG['AddFormName'].'\');window.close();',
    );
  }
  elseif($_GET['tsk'] == 'get_menu_params')
  {

  	if($_GET['resize_win'] == 'y')
  	{
  	  $_FLAGS['ResizeWindowToContentParams'] = __TRUE;
  	}

  	require_once __CFG_PATH_LIBS.__CFG_PATH_CORE."menu.inc";


    $FrontMenu = FrontMenu::getInstance();

    $TypesSelect = array('' => $language['admin']['none']) + $FrontMenu->getMenuModules();
    $ParamsSelect = array('' => array('' => $language['admin']['none'])) + $FrontMenu->getMenuModulesParams();
    $_GET['currval'] = mb_convert_encoding(urldecode($_GET['currval']), "CP1251", "UTF-8");
    $CurrVals = $FrontMenu->setMenuParamsArray($_GET['currval']);

    foreach($CurrVals as $key => $value)
    {      $Item[$key] = $value;
    }

    $_FLAGS['NoReadDB'] = __TRUE;

    if(!isEmptyArr($_POST))
    {
      unset($_POST['act']);
      unset($_POST['key_id']);
      $data = $FrontMenu->setMenuParamsString($_POST);
      if($_POST['module'])
      {
        $html = $TypesSelect[$_POST['module']].' -> '.$ParamsSelect[$_POST['module']][$_POST['params']];
      }
      else
      {      	$html = $TypesSelect[$_POST['module']];
      }
      $output = '
      <div id="text">
       '.$html.'
      </div>
      <script type="text/javascript">
      window.opener.document.getElementById("'.$_GET['elemid'].'").value=\''.mysql_escape_string($data).'\';
      window.opener.document.getElementById("'.$_GET['elemid'].'-list").innerHTML=document.getElementById("text").innerHTML;
      window.close();
      </script>
      ';
      echo $output;
      exit;
    }

    $_SQL_TABLE_FIELDS[$GlobPart] = array(

    			'module' => array(
								'type' => 'select',
								'title' => $language['admin']['type'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['module'],
								//'useInList' => $CONFIG['useInListSort'],
								'values' => $TypesSelect,
								'required' => $CONFIG['AdminReqPatAll'],
								'other' => 'onchange="setparams(this.value);"',
								),

				'params' => array(
								'type' => 'JSselect',
								'title' => $language['admin']['param'],
								'useInAddForm' => 'y',
								'addVariable' => $_POST['param'],
								'useInList' => $CONFIG['useInListSort'],
								'values' => $ParamsSelect,
								'required' => $CONFIG['AdminReqPatAll'],
								'parentID' => 'module',
								),
	);

    $NoUse['BackButton'] = 'y';
    $NoUse['SaveItemButton'] = 'y';
     $ItemButtons['Done'] = array(
  												'cssClass' => '',
  												'newRow' => '',
  												'value' => $language['admin']['doneButton'],
  												'onclick' => 'document.forms[\''.$CONFIG['AddFormName'].'\'].act.value=\'do\';document.forms[\''.$CONFIG['AddFormName'].'\'].submit();',
    );

    $ItemButtons['Cancel'] = array(
  												'cssClass' => '',
  												'newRow' => '',
  												'value' => $language['admin']['cancelButton'],
  												'onclick' => 'window.close();',
    );
  }


  $_SQL_TABLE_EDIT_FORMS[$GlobPart] = array('active');


?>